package com.example.javamaday.leetcode;

import com.example.javamaday.leetcode.base.ListNode;

public class LeetCodeTest0203 {

    public static void main(String[] args) {

    }

    public ListNode removeElements(ListNode head, int val) {

        if (head == null) {
            return null;
        }

        while (head != null && head.val == val) {
            head = head.next;
        }

        ListNode current = head;
        while (current != null) {
            if (current.next != null && current.next.val == val) {
                current.next = current.next.next;
            } else {
                current = current.next;
            }
        }

        return head;
    }
}
